package com.lz.ovuola.service.assembler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.lz.ovuola.entity.UserDo;
import com.lz.ovuola.service.dto.UserDto;
import com.lz.ovuola.util.threadlocal.UserContextHolder;

/**
 * 包装工具
 * 
 * @author fz
 *
 */
public class UserAssembler implements Assembler<UserDto> {

	private Logger logger = LoggerFactory.getLogger("UserAssembler");
	private static UserAssembler UserAssembler = new UserAssembler();

	private UserAssembler() {
		super();
	}

	@Override
	public UserDto toDto(Object object) throws Exception {

		if (object instanceof UserDo) {
			UserDo userDo = (UserDo) object;
			UserDto dto = new UserDto();
			dto.setUserName(userDo.getUserName());
			return dto;
		} else {
			logger.error("---用户id：{},userDo转转userDto过程中出现异常", UserContextHolder
					.get().getUserId());// UserContextHolder
			throw new Exception();
		}
	}

	public UserDto toDtoHeadImage(Object object) throws Exception {

		if (object instanceof UserDo) {
			UserDo userDo = (UserDo) object;
			UserDto dto = new UserDto();
			dto.setHeadImage(userDo.getHeadImage());
			return dto;
		} else {
			logger.error("---用户id：{},userDo转转userDto过程中出现异常", UserContextHolder
					.get().getUserId());// UserContextHolder
			throw new Exception();
		}
	}

	public static UserAssembler getUserAssembler() {
		return UserAssembler;
	}

}
